package com.example.demo.t2;

import java.util.Optional;
import java.util.OptionalInt;
import java.util.Random;
import java.util.Set;
import java.util.concurrent.ExecutionException;
import java.util.concurrent.ForkJoinPool;
import java.util.stream.Collectors;
import java.util.stream.IntStream;
import java.util.stream.Stream;

public class T2_6 {

    public static void main(String[] args) throws Exception {
        System.out.println(Runtime.getRuntime().availableProcessors());
        var r = new Random();

        var arr = IntStream.range(0, 10_000_000)
                .map(x -> r.nextInt(10_000_000))
                .boxed()
                .collect(Collectors.toList());
        var t0 = System.currentTimeMillis();
        System.out.println(arr.stream().max((a,b) -> a-b));
        var t1 = System.currentTimeMillis();
        System.out.println(t1-t0);



        t0 = System.currentTimeMillis();
        System.out.println(arr.parallelStream().max((a,b) -> a-b));
        t1 = System.currentTimeMillis();
        System.out.println(t1-t0);

        t0 = System.currentTimeMillis();
        var pool = new ForkJoinPool(4);
        var res = pool.submit(() -> arr.parallelStream().max((a,b)->a-b)).get();
        System.out.println(res.get());
        t1 = System.currentTimeMillis();
        System.out.println(t1-t0);


    }
}
